﻿using System;
using System.Web.UI;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.Data;
using MTC.Common.Enum;
using MTC.Web.Business;
using MTC.Web.Business.DTO;

namespace MTC.Web.Forms
{
    public partial class PayIns : System.Web.UI.Page
    {
        private ScheduleEntity _entity;
        Business.PayIns PayInsBO = new Business.PayIns();

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                SetupEnvironment();
                //get the driver id if available
                if (Request.Params[Params.SHIFTID] != "0")
                {
                }
            }
        }

        private void SetupEnvironment()
        {
            CboShift.DataSource = ShiftType.GetShiftTypes();
            CboShift.DataBind();
        }

        private void LoadFields()
        {
            if (_entity == null)
                return;

        }

        private void ClearFields()
        {
        }

        private bool SetFields()
        {
            return true;
        }


        protected bool ValidateFields()
        {
            return true;
        }

        protected void BtnSelect_Click(object sender, EventArgs e)
        {
            if (TxtDateofSchedule.Text.Length == 0)
                return;
            DateTime dateOfSchedule = Convert.ToDateTime(TxtDateofSchedule.Text);
            //grdPayIns.DataSource = PayInsBO.GetASchedule(dateOfSchedule, Convert.ToInt32(CboShift.SelectedItem.Value));
            grdPayIns.DataBind();
        }

        protected void btnExcel_Click(object sender, ImageClickEventArgs e)
        {
            GrdExport.WriteXlsToResponse();
        }

        protected void btnPdf_Click(object sender, ImageClickEventArgs e)
        {
            GrdExport.WritePdfToResponse();
        }

        protected void btnRtf_Click(object sender, ImageClickEventArgs e)
        {
            GrdExport.WriteRtfToResponse();
        }

        protected void grdPayIns_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            PayInScheduleEntity payInScheduleEntity = (PayInScheduleEntity)grdPayIns.GetRow(grdPayIns.EditingRowVisibleIndex);
            // Find the controls
            ASPxDateEdit txtPayInDate = (ASPxDateEdit)grdPayIns.FindEditFormTemplateControl("txtPayInDate");
            e.NewValues["TaxiId"] = payInScheduleEntity.TaxiId;
            e.NewValues["DriverId"] = payInScheduleEntity.DriverId;
            e.NewValues["ShiftId"] = payInScheduleEntity.ScheduleId;
            e.NewValues["PayInId"] = payInScheduleEntity.PayInId;
            e.NewValues["Platenumber"] = payInScheduleEntity.Platenumber;
            e.NewValues["PayInDate"] = txtPayInDate.Date;


        }

        protected void grdPayIns_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
        {
            if (grdPayIns.IsEditing && !grdPayIns.IsNewRowEditing)
            {
                PayInScheduleEntity payInScheduleEntity =
                    (PayInScheduleEntity)grdPayIns.GetRow(grdPayIns.EditingRowVisibleIndex);
                // Find the controls
                ASPxDateEdit txtPayInDate = (ASPxDateEdit)grdPayIns.FindEditFormTemplateControl("txtPayInDate");
                if (payInScheduleEntity.PayInDate.HasValue)
                    txtPayInDate.Date = (DateTime)payInScheduleEntity.PayInDate;
            }

        }

        protected void grdPayIns_RowUpdated(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e)
        {

        }


        protected void UsersGridRowInserting(object sender, ASPxDataInsertingEventArgs e)
        {
        }

        protected void UsersGridCustomErrorText(object sender, ASPxGridViewCustomErrorTextEventArgs e)
        {
        }

        protected void UsersGridHtmlEditFormCreated(object sender, ASPxGridViewEditFormEventArgs e)
        {
        }
    }
}
